
import { createStore } from "redux"
import { Hide_Toast, Show_Toast } from "./ActionType";

const defState:IRootState={
    // 所有跟toast相关的数据
    toastData:{
       isShow:false,
       message:"测试信息",
       type:"success"
    }
}

const reducer=(state:IRootState=defState,action:IStateAction)=>{
    state=JSON.parse(JSON.stringify(state))
    // 通过action进行判断，是否展示toast
    switch(action.type){
        case Show_Toast:
            // payload
            // 还要把message和type 也修改
            state.toastData = action.pyload;
            // 把isShow改为true
            state.toastData.isShow=true
        break;
        case Hide_Toast:
            // 只需要把isShow变成false
            state.toastData.isShow=false
            break;
    }
    return state;
}

 const store = createStore(reducer)
 export default store;